/**
 * 
 */
package org.seginfo.httpfuzzer.header.impl;

import java.util.HashSet;
import java.util.Set;

import org.seginfo.httpfuzzer.generation.RandomSelector;
import org.seginfo.httpfuzzer.generation.UniformRandomSelector;
import org.seginfo.httpfuzzer.header.AttackStrategy;
import org.seginfo.httpfuzzer.header.HeaderPropertyImpl;

/**
 * @author Administrador
 *
 */
public class Range extends HeaderPropertyImpl {
	
	private static final String NAME = "Range";
	private static final String VALID = "bytes=0-100";
	//private static final String WILDCARD = "*/*";
	private static final int BAD_STRING_MIN_LENGTH = 8;
	private static final int BAD_STRING_LENGTH = 400;

	/**
	 * @param attackStrategy
	 */
	public Range(AttackStrategy attackStrategy) {
		super(attackStrategy);
		this.value = this.generateValue();
	}

	/**
	 * @see org.seginfo.httpfuzzer.header.HeaderPropertyImpl#getName()
	 */
	public String getName() {
		return NAME;
	}

	/**
	 * @return
	 */
	private String generateValue() {
		
		String rv = ""; //VALID;

		/* casos
		 * - bytes 11-9
		 * - bytes 11111111111111111111111111-9999999999999999999999999999999
		 * - bytes aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa-bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
		 * - bad string
		 * - bytes=badstring-badstring
		 */

		Set cases = new HashSet();
		cases.add("bytes=111-9");
		cases.add("bytes=111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111-999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999");
		cases.add("bytes=aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa-bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb");
		cases.add("bytes=500-600,601-999");
		cases.add(attackStrategy.getStringAttack(BAD_STRING_MIN_LENGTH, BAD_STRING_LENGTH));
		cases.add("bytes="+attackStrategy.getStringAttack(BAD_STRING_MIN_LENGTH, BAD_STRING_LENGTH)+"-"+attackStrategy.getStringAttack(BAD_STRING_MIN_LENGTH, BAD_STRING_LENGTH));
		
		RandomSelector casesSelector = new UniformRandomSelector(cases);

		rv = (String) casesSelector.selectOne();
		return rv;
	}

}
